package com.iclippi.server;

import java.util.logging.Logger;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.iclippi.client.ClipboardLoadData;
import com.iclippi.client.ClipboardService;
import com.iclippi.server.model.Clipboard;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class ClipboardServiceImpl extends RemoteServiceServlet implements
		ClipboardService {

	private static final Logger log = Logger.getLogger(ClipboardServiceImpl.class.getName());
	
	
	@Override
	public ClipboardLoadData clipboardLoad(String clipboardName) {
		log.info("Load - "+clipboardName);		//TODO Doesn't work on the App Engine 
		Clipboard clipboard=Clipboard.getClipboard(clipboardName);
		return new ClipboardLoadData(clipboard.getContent(),clipboard.getVersion(),clipboard.getName());
		
	}

	@Override
	public long clipboardSave(String clipboardName, String content) {
		log.info("Save - "+clipboardName);		//TODO Doesn't work on the App Engine
		Clipboard clipboard=Clipboard.getClipboard(clipboardName);
		clipboard.updateClipboard(content);
		Long version=clipboard.getVersion();
		return version;
	}

	@Override
	public long clipboardGetVersion(String clipboardName) {
		log.info("Clipboard ID - "+clipboardName);
		Clipboard clipboard=Clipboard.getClipboard(clipboardName);
		return clipboard.getVersion();
	}
}
